from django.http import JsonResponse


class Code:
    OK = '0'
    ERRPARAMS = '8130'
    ERRVERIFY = '8131'
    ERRBUSY = '8132'
    ERRPATTERN = '8133'


error_map = {
    Code.OK: '成功',
    Code.ERRPARAMS: '参数错误',
    Code.ERRVERIFY: '验证失败',
    Code.ERRBUSY: '请求请求频繁',
    Code.ERRPATTERN: '格式错误',
}


def ResultResponse(errno=Code.OK, errmsg='', data=None, **kwargs):
    json_dict = {'errno': errno, "errmsg": errmsg, 'data': data}
    if kwargs:
        json_dict.update(kwargs)
    return JsonResponse(json_dict)
